package com.emm.yixun.mobile.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.model.GetMarketingControlList.RoomList;
import com.emm.yixun.mobile.ui.housing.HouSingResourcesDetailsActivity;

public class Marketing_Grid_Adapter extends BaseAdapter {

	Context context;

	ArrayList<RoomList> list;

	ArrayList<String> l = new java.util.ArrayList<String>();
	ArrayList<String> l2 = new java.util.ArrayList<String>();
	ArrayList<Integer> l3 = new ArrayList<Integer>();

	private void SetL() {
		l.add("可售");
		l.add("小订");
		l.add("认购");
		l.add("签约");
		l.add("销控");
		l.add("保留");
		l.add("暂不可售");
	}

	private void SetL2() {
		l3.add(R.drawable.select_housing_bg_lines1);
		l3.add(R.drawable.select_housing_bg_lines2);
		l3.add(R.drawable.select_housing_bg_lines3);
		l3.add(R.drawable.select_housing_bg_lines4);
		l3.add(R.drawable.select_housing_bg_lines5);
		l3.add(R.drawable.select_housing_bg_lines6);
		l3.add(R.drawable.select_housing_bg_lines7);
	}

	public Marketing_Grid_Adapter(Context context, ArrayList<RoomList> list) {
		this.list = list;
		this.context = context;
		SetL();
		SetL2();
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? null : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHoudlerGrid v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.marketing_grid_item, null);
			v = new ViewHoudlerGrid();
			v.bg_item_grid = (LinearLayout) convertView.findViewById(R.id.bg_item_grid);
			v.content_item_grid = (TextView) convertView.findViewById(R.id.content_item_grid);
			convertView.setTag(v);
		} else {
			v = (ViewHoudlerGrid) convertView.getTag();
		}
		v.content_item_grid.setTextColor(Color.parseColor("#ffffff"));
		if (l.get(0).equals(list.get(position).getRoomStatus())) {
			v.content_item_grid.setTextColor(Color.parseColor("#959595"));
			v.bg_item_grid.setBackgroundResource(l3.get(0));
		} else if (l.get(1).equals(list.get(position).getRoomStatus()) || "认筹".equals(list.get(position).getRoomStatus())) {
			v.bg_item_grid.setBackgroundResource(l3.get(1));
		} else if (l.get(2).equals(list.get(position).getRoomStatus())) {
			v.bg_item_grid.setBackgroundResource(l3.get(2));
		} else if (l.get(3).equals(list.get(position).getRoomStatus())) {
			v.bg_item_grid.setBackgroundResource(l3.get(3));
		} else if (l.get(4).equals(list.get(position).getRoomStatus())) {
			v.bg_item_grid.setBackgroundResource(l3.get(4));
		} else if (l.get(5).equals(list.get(position).getRoomStatus())) {
			v.bg_item_grid.setBackgroundResource(l3.get(5));
		} else {
			v.bg_item_grid.setBackgroundResource(l3.get(6));
		}
		v.content_item_grid.setText(list.get(position).getRoomName());

		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				intent.setClass(context, HouSingResourcesDetailsActivity.class);
				intent.putExtra("roomId", list.get(position).getRoomId());
				context.startActivity(intent);
			}
		});

		return convertView;
	}

	public static class ViewHoudlerGrid {
		LinearLayout bg_item_grid;

		TextView content_item_grid;
	}

}
